<?php 
class zt_smsServiceDriver extends smsServiceDriver
{
private $cfg = array();
private $Gateway = 'http://www.ztsms.cn/';
public function config($cfg)
{
$this->cfg = $cfg;
}
public function IMSend($phone,$content)
{
if (false != $exids = $this->BC_EXPS($phone,$content,$this->cfg['bcmax']))
{
return '@exps('.count($exids).')';
}
$this->Gateway = base64_decode('aHR0cDovL3d3dy56dHNtcy5jbi8=');
if ($this->cfg['sign']) {
$smsb = $sms = $content.'【'.$this->cfg['sign'].'】';
}else{
$smsb = $sms = $content;
}
if (ENC_IS_GBK) $sms = ENC_G2U($sms);
if (strlen($phone) >13) $phone = str_replace(';',',',$phone);
$url  = $this->Gateway;
$url .= 'sendXSms.do?';
$post = 'username='.$this->cfg['account'].'&password='.$this->cfg['password'].'&mobile='.$phone.'&content='.rawurlencode($sms).'&productid='.$this->cfg['productid'].'&xh='.$this->cfg['xh'];
$this->Debug('Request: Started');
$this->Debug('Send: '.htmlspecialchars($smsb));
$result = $this->Get($url,$post);
if ($result == '')
{
$this->Error('Connected Failed.');
return $this->result_error('reponse-empty');
}
$this->Debug('Response: '.htmlspecialchars($result));
$match = explode(',',$result);
$code = $match[0];
if ($this->IMSend_IS_SUCC($code))
{
$this->Debug('Status: Send success.');
}
return $this->result_success(
$this->IMSend_STATUS($code),
array(
'raw'=>$result,
'status'=>($this->IMSend_IS_SUCC($code) ?'success': 'failed')
)
);
}
public function IMStatus()
{
$url  = $this->Gateway;
$url .= 'balance.do?';
$url .= '&username='.$this->cfg['account'].'&password='.$this->cfg['password'].'&productid='.$this->cfg['productid'];
$result = $this->Get($url);
if ( (int)$result >0)
{
$status = '响应正常';
}
else
{
$status = '响应异常';
}
return sprintf('通道状态：%s<br/>短信剩余：%d 条',$status,$result);
}
private function IMSend_IS_SUCC($code)
{
if ( (int)$code === 1)
{
return true;
}
else
{
return false;
}
}
private function IMSend_STATUS($code)
{
$code_STA = array(
'-1'=>'用户名或者密码不正确',
'0'=>'短信提交失败',
'1'=>'短信提交成功',
'2'=>'余额不够',
'3'=>'扣费失败（请联系客服）',
'5'=>'短信定时成功',
'6'=>'有效号码为空',
'7'=>'短信内容为空',
'8'=>'没有签名',
'9'=>'没有Url提交权限',
'10'=>'发送号码过多,最多支持500个号码',
'11'=>'产品ID异常',
'12'=>'参数异常',
'13'=>'30分钟重复提交',
'14'=>'用户名或密码不正确，产品余额为0，禁止提交',
'15'=>'Ip验证失败',
'19'=>'短信内容过长，最多支持500个',
'20'=>'定时时间不正确',
);
if (isset($code_STA[$code]))
{
return $code_STA[$code];
}
else
{
return 'ERROR';
}
}
}
?>